package org.geektimes.projects.user.management.jolokia;

import org.geektimes.projects.user.management.JpMBean;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2021/3/17 7:52
 */
@JpMBean
public class Calculator implements CalculatorMXBean {

    private Integer x = 0;
    private Integer y = 0;


    @Override
    public Integer getX() {
        return x;
    }

    @Override
    public void setX(Integer x) {
        this.x = x;
    }

    @Override
    public Integer getY() {
        return y;
    }

    @Override
    public void setY(Integer y) {
        this.y = y;
    }

    /**
     * 加法
     * @return
     */
    @Override
    public int add() {
        return x + y;
    }

    /**
     * 减法
     * @return
     */
    @Override
    public int reduce() {
        return x - y;
    }

    /**
     * 乘法
     * @return
     */
    @Override
    public int mul() {
        return x * y;
    }


    /**
     * 除法
     * @return
     */
    @Override
    public int div(){
        if(x ==0){
            throw new RuntimeException("被除数不能等于0");
        }
        return x / y;
    }


}
